package com.apesay.service.utils;

import com.alibaba.fastjson.JSONObject;
import com.apesay.exception.ServiceException;
import com.apesay.service.base.ClientService;
import com.apesay.utils.Constant;
import com.apesay.utils.DataUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 
 * ClassName: VoucherService 
 * date: 2015年10月29日 上午10:39:21 
 *
 * @author sid
 */
@Component
public class UtilsService {

	protected static Logger logger = LoggerFactory.getLogger(UtilsService.class);
	
	@Autowired
	private ClientService clientService;

	/**
	 * 
	 * getOne:
	 *
	 * @author sid
	 * @param where
	 * @return
	 */
	public JSONObject getOne(JSONObject where,String model){
		try {
			JSONObject findObject= clientService.find(where.toJSONString(), "{}", "{}",model,0,1);
			if (DataUtils.isNotEmpty(findObject)&&findObject.getJSONObject(Constant.RESULT).getIntValue("count")>0) {
				return findObject.getJSONObject(Constant.RESULT).getJSONArray(Constant.RESULTS).getJSONObject(0);
			}
		} catch (ServiceException e) {
			e.printStackTrace();
		}
		return null;
	}
}
